/**
 * create by young (young2f@outlook.com) on 2023/7/23
 */
'use strict';
const fs = require('fs');

const data={
    "reported": {
        "DDL": 0,
        "GWD": 23.83355140686035,
        "GYWD": 0,
        "HDDS": 0,
        "JDDP": 0,
        "JYWD": 23.13368034362793,
        "LJZCL": 0,
        "PH": 7.295211315155029,
        "QDQL": 0,
        "ROSYL": 0.1920572817325592,
        "SBMS": 3,
        "SBZT": 9,
        "SCCL": 46872,
        "SDSD": 100,
        "SJSD": 0,
        "TJDM": 11,
        "WSD": 2304
    }
}
const json={deviceData:data}
const dataMapping=fs.readFileSync('./dataMapping.txt','utf8')
const func = dataMapping.substring(dataMapping.indexOf('{'), dataMapping.length);
const val = dataMapping.substring(dataMapping.indexOf('(') + 1, dataMapping.indexOf(')'));

//  console.log('jsonn',json)
const cmd = `let ${val}=${JSON.stringify(json)}; (function () ${func})`;
const params = eval(cmd)();
console.log(params)
// function fun(data){
//     const {reported}=data
//     const _=require('lodash')
//     const params=[]
//     _.map(reported,(value,name)=>{
//               params.push({name,value})
//     })
//     return params
// }


